<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\ShopOrder;
use app\admin\model\User;
use app\admin\model\ShopOrderFoods;
use app\admin\model\ShopList;
use app\admin\model\ShopCategory;
use app\admin\model\ShopFoods;
use app\admin\model\ShopAttribute;
use app\admin\model\FoodsSpec;
class CommonController extends BaseController{
	//查询订单信息
	public function selectOrder($page,$limit){
		$order=new ShopOrder();
		$orderlist=$order->page($page,$limit)->select();
		$userlist=array();
		$shoplist=array();
		foreach($orderlist as $orders){
			$userlist[]=$orders->user;
			$shoplist[]=$orders->shopname;
		}
		$allcount=count($order->select());
		$orderarr=array();
		$orderarr[]=$orderlist;
		$orderarr[]=$userlist;
		$orderarr[]=$shoplist;
		$orderarr[]=$allcount;
		return $orderarr;
	}
	//添加订单信息
	public function insertOrder($data){
		$order=new ShopOrder();
		return $order->save($data);
	}
	//修改订单信息
	public function updateOrder($where,$data){
		$order=ShopOrder::where($where)->find();
		return $order->save($data);
	}
	public function deleteOrder($where){
		return ShopOrder::destroy($where);
	}
	//添加用户信息
	public function insertUser($data){
		$user=new User();
		return $user->save($data);
	}
	//查询员工信息
	public function selectEmployee($where){
		$user=new User();
		return $user->where($where)->select();
	}
	//添加订单菜品信息
	public function insertOrderFoods($data){
		$ShopOrderFoods=new ShopOrderFoods();
		return $ShopOrderFoods->save($data);
	}
	//修改订单菜品信息
	public function updateOrderFoods($where,$data){
		$ShopOrderFoods=new ShopOrderFoods();
		$orderFoods=$ShopOrderFoods->where($where)->find();
		return $orderFoods->save($data);
	}
	//删除订单菜品信息
	public function deleteOrderFoods($where){
		return ShopOrderFoods::destroy($where);
	}
	//查询订单菜品信息
	public function selectOrderFoods($data){
		$ShopOrderFoods=new ShopOrderFoods();
		return $ShopOrderFoods->where($data)->find();
	}
	//查询订单中相同的菜
	public function selectSameOrderFoods($data){
		$ShopOrderFoods=new ShopOrderFoods();
		return $ShopOrderFoods->where($data)->select();
	}
	//查询订单菜品信息
	public function selectAllOrderFoods($where){
		$ShopOrderFoods=new ShopOrderFoods();
	    return $ShopOrderFoods->where($where)->select();
	}
	//查询所有订单里面的菜品信息
	public function selectOrderFoodsAll(){
		$ShopOrderFoods=new ShopOrderFoods();
	    return $ShopOrderFoods->all();
	}
	//添加店铺菜品信息
	public function insertShopCategory($data){
	    $ShopCategory=new ShopCategory();
		return $ShopCategory->save($data);
	}
	//查询店铺列表信息
	public function selectShopList(){
		$ShopList=new ShopList();
		return $ShopList->all();
	}
	//查询店铺详情
	public function selectShopInfo($data){
		$ShopList=new ShopList();
		return $ShopList->where($data)->find();
	}
	//查询菜品分类信息
	public function selectShopCategory(){
		$shop_id=input('param.shop_id');
		$data['shop_id']=$shop_id;
		$ShopCategory=new ShopCategory();
		return $ShopCategory->where($data)->all();
	}
	public function selectShopFoods(){
		$category_id=input('param.category_id');
		$data['category_id']=$category_id;
		$ShopFoods=new ShopFoods();
		return $ShopFoods->where($data)->all();
	}
	//查询规格信息
	public function selectFoodsSpec(){
		$food_id=input('param.food_id_spec');
		$wherefooid['food_id']=$food_id;
		$FoodsSpec=new FoodsSpec();
		$foodsSpeclist = $FoodsSpec->where($wherefooid)->select();
		$attributelist=array();
		foreach ($foodsSpeclist as $item){
			$attributelist[]=$item->ShopAttribute;
		}
		$allarray=array();
		$allarray[]=$foodsSpeclist;
		$allarray[]=$attributelist;
		return $allarray;
	}
	//查询规格以及值
	public function selectFoodsSpecll($data){
		$FoodsSpec=new FoodsSpec();
		$foodsSpeclist = $FoodsSpec->where($data)->select();
		$attributelist=array();
		foreach ($foodsSpeclist as $item){
			$attributelist[]=$item->ShopAttribute;
		}
		$allarray=array();
		$allarray[]=$foodsSpeclist;
		$allarray[]=$attributelist;
		return $allarray;
	}
	//查询菜品分类信息
	public function selectShopFoodsSpec($data){
		$FoodsSpec=new FoodsSpec();
		return $FoodsSpec->where($data)->select();
	}
	//查询规格属性值信息
	public function selectFoodsinfo($data){
		$ShopFoods=new ShopFoods();
		return $ShopFoods->where($data)->find();
	}
	//查询店铺菜品信息
	public function selectShopFoodsInfo($data){
		$ShopFoods=new ShopFoods();
		return $ShopFoods->where($data)->find();
	}
	//查询规格属性值信息
	public function selectFoodsAttr($id){
		$data['id']=$id;
		$ShopAttribute=new ShopAttribute();
		return $ShopAttribute->where($data)->find();
	}
}
?>